package com.sky.mapper;

import com.sky.entity.ShoppingCart;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface ShoppingCartMapper {

    // 根据用户id + 菜品id 或查 用户id + 套餐id 查询购物车表是否存在(添加购物车) (删减购物车)
    ShoppingCart findOne(ShoppingCart shoppingCart);

    //如果存在,数量加1, 更新数据库(添加购物车) (更新购物车)
    void update(ShoppingCart shoppingCartDB);

    // 插入数据库并保存(添加购物车)
    @Insert("insert into shopping_cart values (null,#{name},#{image},#{userId},#{dishId},#{setmealId}," +
                                               "#{dishFlavor},#{number},#{amount},#{createTime})")
    void insert(ShoppingCart shoppingCart);

    // 根据用户id查询购物车
    @Select("select * from shopping_cart where user_id = #{userId}")
    List<ShoppingCart> findList(Long userId);

    // 清空购物车
    @Delete("delete from shopping_cart where user_id = #{userId}")
    void delete(Long userId);
}
